package com.nlscan.qdkit.ui.publico.config;

import com.nlscan.qdkit.ui.publico.util.SpUtil;
import com.nlscan.qdkit.common.core.app.App;
import com.quvii.qvlib.util.ScreenUtil;

/**
 * APP 全局变量类 标志位
 * Created by dyp on 2018/1/26.
 */

public class PublicoVariate {

    /**
     * sdk 相关
     */
    public static boolean IS_OPEN_SDK_LOG = false; // 判断是否已经打开sdk侧.so文件日志的标志位

    /**************************
     * 用户信息相关 BEGIN
     ***************************/


    public static Integer authMode;           // 登录认证方式

    private static volatile boolean loginStatus = false; //是否登录成功，如果没有登录成功，在点击报警推送时，走loadingActvity；如果登录成功了，点击报警推送时，走MainTabActivity

    public static boolean isLoginSuccess() {
        return loginStatus;
    }

    public static void setIsLoginSuccess(boolean success) {
        loginStatus = success;
    }

    /**************************
     * 用户信息相关 END
     ***************************/

    /*
     * Module-Playback BEGIN
     */

    //[第二套UI]快速切换回放日期，标识当前窗口下选中的日期 格式20210719
    //[bugFix]修复左右滑动WeekView,选中日期自动变化问题
    private static volatile String chooseCalendarStr = "";

    /*
     * Module-Playback END
     */


    /**************************
     * Module-Device BEGIN
     ***************************/


    /**
     * 标记预览/回放选择通道快速跳转到添加设备页面
     */
    private static volatile boolean isNeedJumpToScan = false;


    /**************************
     * Module-Device END
     ***************************/




    /**************************
     * Module-Share END
     ***************************/

    /**************************
     * Module-Config BEGIN
     ***************************/
    public static boolean isPadMode = false;


    /**************************
     * Module-Config END
     ***************************/


    /**************************
     * UI 处理相关 BEGIN
     ***************************/

    /*** 屏幕宽度 */
    private static int SCREEN_WIDTH = -1;

    /*** 屏幕高度 */
    private static int SCREEN_HEIGHT = -1;

    /**
     * 底部虚拟导航栏显示状态（该标志位当前只适配三星s8 底部导航栏）
     * 0 == 显示
     * 2 == 隐藏
     * 6 ==
     * todo 使用ScreenUtils来替代
     */
    public static int VIRTUAL_NAVIGATION_BAR_STATE = 0;


    public static boolean isFirstLoadPreview = false;

    public static boolean isFromHelpFrag = false;//用户是否点击了帮助界面

    /**
     * 是否处于预览或回放模块，预览和回放时解除强制竖屏
     * todo fenxi
     */
    public static boolean isInPreviewOrPlaybackModule = false;

    /**
     * 播放窗口 PagedGrid 的宽度
     * -- 适配横屏刘海屏窗口大小计算异常问题（只处理横屏场景）
     */
    private static volatile int playWindowWidth = -1;


    private static volatile int playWindowHeight = -1;


    /**************************
     * UI 处理相关 END
     ***************************/


    /**************************
     * 业务逻辑 相关 BEGIN
     ***************************/

    /**
     * 是否点击报警信息或点击设备预览进入，或者点击回放底部按钮跳转到预览
     */
    public static boolean isFromAlarmOrDeviceFrg = false;

    /*** 是否为预览跳转到回放页面 底部菜单项 */
    public static boolean isPreviewJumpPlayback = false;
    /*** 是否为回放跳转到预览页面 底部菜单项 */
    public static boolean isPlaybackJumpPreview = false;

    private static String albumPath = "";
    private static String videoPath = "";

    public static String presetPath = null;

    private volatile static String currentFragmentTag;


    /**************************
     * 业务逻辑 相关 END
     ***************************/


    /**************************
     * 播放逻辑 相关 BEGIN
     ***************************/


    /**
     * 判断是否停止预览、回放 回收 playerCore (stop操作)的后台线程任务
     * -- 注销时将标志位置为 false
     * todo low rename
     */
    public static boolean isPcNeedStop = false;


    /**************************
     * 播放逻辑 相关 END
     ***************************/


    /**************************
     * 报警相关 BEGIN
     ***************************/


    /**
     * 报警列表上次刷新时间（ms）
     */
    public static long alarmInfoLastRefreshTime;

    public static String remoteVideoDownloadCachePath;

    /**************************
     * UI 处理相关 BEGIN
     ***************************/

    public static int getScreenWidth() {
        if (SCREEN_WIDTH <= 0) {
            SCREEN_WIDTH = ScreenUtil.getScreenWidth(App.getInstance());
        }

        return SCREEN_WIDTH;
    }

    public static void setScreenWidth(int screenWidth) {
        SCREEN_WIDTH = screenWidth;
    }

    public static int getScreenHeight() {
        if (SCREEN_HEIGHT <= 0) {
            SCREEN_HEIGHT = ScreenUtil.getScreenHeight(App.getInstance());
        }

        return SCREEN_HEIGHT;
    }

    public static void setScreenHeight(int screenHeight) {
        SCREEN_HEIGHT = screenHeight;
    }

    public static int getPlayWindowWidth() {
        return playWindowWidth;
    }

    public static void setPlayWindowWidth(int playWindowWidth) {
        PublicoVariate.playWindowWidth = playWindowWidth;
    }

    public static int getPlayWindowHeight() {
        return playWindowHeight;
    }

    public static void setPlayWindowHeight(int playWindowHeight) {
        PublicoVariate.playWindowHeight = playWindowHeight;
    }

    /**************************
     * UI 处理相关 END
     ***************************/

    /**************************
     * 报警相关 END
     ***************************/



    public static String getAlbumPath() {
        return albumPath == null ? (albumPath = "") : albumPath;
    }

    public static void setAlbumPath(String albumPath) {
        PublicoVariate.albumPath = albumPath;
    }

    public static String getVideoPath() {
        return videoPath == null ? (videoPath = "") : videoPath;
    }

    public static void setVideoPath(String videoPath) {
        PublicoVariate.videoPath = videoPath;
    }

    public static String getPresetPath() {
        return presetPath == null ? (presetPath = "") : presetPath;
    }

    public static void setPresetPath(String presetPath) {
        PublicoVariate.presetPath = presetPath;
    }

    /**
     * 兼容IOT迁移代码 BEGIN
     */


    /**
     * 兼容IOT迁移代码 END
     */
    public static boolean isInStart = true;    //是否在启动界面, 若在启动界面, 则会在sdk初始化完成之后触发自动登录功能

    /**
     * 获取账号id, 该id只可以在本地功能中使用, 在例如分享功能中不可用该字段
     * 可用于所有的模式
     *
     * @return 账号id
     */





    public static void init() {
        isPadMode = SpUtil.getInstance().isPadMode();
    }



    public static String fragmentTagPreview = PublicoConst.FRAGMENT_TAG_NULL;
    public static String fragmentTagPlayback = PublicoConst.FRAGMENT_TAG_NULL;
    public static String fragmentTagDeviceList = PublicoConst.FRAGMENT_TAG_NULL;
    public static String fragmentTagShareList = PublicoConst.FRAGMENT_TAG_NULL;
    public static String fragmentTagAlarmList = PublicoConst.FRAGMENT_TAG_NULL;
    public static String fragmentTagAlbum = PublicoConst.FRAGMENT_TAG_NULL;
    public static String fragmentTagConfig = PublicoConst.FRAGMENT_TAG_NULL;

    public static String getCurrentFragmentTag() {
        return currentFragmentTag == null ? (currentFragmentTag = "") : currentFragmentTag;
    }

    public static void setCurrentFragmentTag(String currentFragmentTag) {
        PublicoVariate.currentFragmentTag = currentFragmentTag;
    }

    public static boolean getIsNeedJumpToScan() {
        boolean value = isNeedJumpToScan;
        isNeedJumpToScan = false;
        return value;
    }

    public static void setIsNeedJumpToScan(boolean isNeedJumpToScan) {
        PublicoVariate.isNeedJumpToScan = isNeedJumpToScan;
    }

    public static String getChooseCalendarStr() {
        return chooseCalendarStr == null ? (chooseCalendarStr = "") : chooseCalendarStr;
    }

    public static void setChooseCalendarStr(String chooseCalendarStr) {
        PublicoVariate.chooseCalendarStr = chooseCalendarStr;
    }
}
